//
// Created by sgyt on 2020/6/17.
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>


//警用断字符
int main(int argc,char *argv[])
{
    struct termios term;
    long vdisable;

    //判断文件描述是否是终端设备
    if(!isatty(STDIN_FILENO))
    {
        printf("standard input is not a terminal device");
        exit(EXIT_FAILURE);
    }

    //获取终端设备的相关能力
    if((vdisable = fpathconf(STDIN_FILENO,_PC_VDISABLE)) <0)
    {
        printf("fpathconf error or _PC_VDISABLE not in effect");
        exit(EXIT_FAILURE);
    }

    //判断该终端设备是否具有禁用字符的功能
    if(tcgetattr(STDIN_FILENO,&term) < 0)
    {
        perror("tcgetattr is error");
        exit(EXIT_FAILURE);
    }

    term.c_cc[VINTR] = vdisable;
    term.c_cc[VEOF] = 2;

    //设置终端属性
    if(tcsetattr(STDIN_FILENO,TCIFLUSH,&term) < 0)
    {
        perror("tcsetattr is error");
        exit(EXIT_FAILURE);
    }

    return 0;
}

